# Maintainer: Lukas Fleischer <lfleischer@archlinux.org>
# Maintainer: David Runge <dvzrv@archlinux.org>
# Contributor: Hilton Medeiros <medeiros.hilton@gmail.com>
# Contributor: Dave Reisner <d@falconindy.com>

pkgname=libgit2
pkgver=1.2.0
pkgrel=1
epoch=1
pkgdesc='A linkable library for Git'
arch=('x86_64')
url="https://libgit2.github.com/"
depends=('glibc' 'http-parser' 'openssl' 'pcre' 'zlib')
makedepends=('cmake' 'libssh2' 'python')
provides=('libgit2.so')
license=('GPL2')
source=("$pkgname-$pkgver.tar.gz::https://github.com/libgit2/libgit2/archive/v${pkgver}.tar.gz"
        "${pkgname}-1.2.0-remove_http-parse_incompatible_tests.patch")
sha512sums=('428188de153fdf8ff5bf78949f4a3a89fba57b87a8b641f92fed501df6a8cfdb72e0ffe0bf61a98adf210a2867134eb4421ea4b8d8219331aabc3daddd92f5fc'
            '01bf3a960b2e6d441017af363bff267bd1513915ebefda95012d7feb38f7020778ea0908664cc479da82f441a4dd2788772005006a9c19e87cfc234268dc3785')
b2sums=('b612e3a30b4675431879792132adee22cce57986b4f307507b896d823329f7e37514d9008e008075c395a4eca26aaf6ed6eb3943cf97370a0b04086240a5e1fc'
        'e725fb41c9bdfd9952693c9c47be90c10a16a78ab91f80e74c40c5510a83325575ce95674a2e21282e9c300f2bc8d430c896fa379ef744b8a8a912729fa88827')

prepare() {
  cd "$pkgname-$pkgver"
  # remove tests that are only compatible with the (modified) vendored version
  # of http-parser, but not with upstream http-parser
  patch -Np1 -i "../${pkgname}-1.2.0-remove_http-parse_incompatible_tests.patch"
}


build() {
  cd "$pkgname-$pkgver"
  cmake -DCMAKE_INSTALL_PREFIX=/usr \
        -DCMAKE_BUILD_TYPE='None' \
        -DUSE_HTTP_PARSER=system \
        -DTHREADSAFE=ON \
        -Wno-dev \
        -B build \
        -S .
  make -C build VERBOSE=1
}

check() {
  cd "$pkgname-$pkgver"
  make -C build test VERBOSE=1
}

package() {
  depends+=('libssh2.so')
  cd "$pkgname-$pkgver"
  make -C build DESTDIR="$pkgdir" install
  install -vDm 644 {AUTHORS,README.md} \
    -t "${pkgdir}/usr/share/doc/${pkgname}"
}
